package DateWork;

import javafx.scene.input.DataFormat;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Date_ {
    public static void main(String[] args) {
        System.out.println(new Date());
        //long转date
        Date date = new Date(98989);
        System.out.println(date);
        //date 转换成long
        Long time = date.getTime();
        System.out.println(time);
        //string 和date转换
        Date date1 = new Date();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        df.format(date1);
        try {
            Date parse = df.parse("2021-12-20");
            System.out.println(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar cal = Calendar.getInstance();
        int i = cal.get(Calendar.MONTH);
        System.out.println(i);
        int i1 = cal.get(Calendar.YEAR);
        System.out.println(i1);

    }
}
